package com.xinjiang.electricpower.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.xinjiang.electricpower.domain.TgManageUser;
import com.xinjiang.electricpower.service.ITgManageUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author feizhao
 * @date 2022/12/7
 * @apiNote 台区管理用户控制层类
 */

@RestController
@RequestMapping("/xinjiang-power-supply-station/tg-manager-user/")
@Api(value = "台区管理用户控制层类", tags = "台区管理用户控制层类")
@Validated//有此注解，才会校验游离的参数
@Slf4j
@RequiredArgsConstructor
public class TgManageUserController {

    private final ITgManageUserService tgManageUserService;


    /**
     * @return R<List <TgManageUser>> 查询台区管理用户
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询台区管理用户", notes = "查询台区管理用户")
    public R<List<TgManageUser>> getXjOrderGeneralProcess() {
        List<TgManageUser> tgManageUser = tgManageUserService.list();
        return R.ok(tgManageUser, "查询成功");
    }
    /**
     * @return R<Long> 返回结果
     * @description 新增
     */
    @PostMapping("/insert")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增", notes = "新增")
    public R<Object> addTgManageUsers() {

        List<TgManageUser> list = new ArrayList<TgManageUser>();
        TgManageUser tgManageUser = new TgManageUser();
        tgManageUser.setConsNo("60201").setConsName("张三").setTgManager("李四").setBarCode("1111111111");
        TgManageUser tgManageUser1 = new TgManageUser();
        tgManageUser1.setConsNo("60202").setConsName("张二").setTgManager("王武").setBarCode("2222222222");
        list.add(tgManageUser);
        list.add(tgManageUser1);
        boolean flag = tgManageUserService.saveBatch(list);
        if (flag) {
            return R.ok();
        }
        return R.fail("操作失败");
    }

}
